import React, {useState, useEffect, useRef} from 'react'
import {Space, Modal, message} from 'antd';
import { ProFormDateRangePicker, ProTable} from '@ant-design/pro-components';
import TheButton from "@/components/TheButton/index.jsx";
import {apiPostTimedTaskResult} from "@/api/couponManagement/timeTask.jsx";
import moment from 'moment';
import {useLocation, useNavigate} from "react-router-dom";
import GoBack from "@/components/TheGoBack/index.jsx";

const { confirm } = Modal
export default (props) => {
    const location = useLocation();
    const actionRef = useRef();
    const columns = [
        {
            title: "券id",
            dataIndex: "couponId",
            key: "couponId",
        },
        {
            title: "券名称",
            dataIndex: "couponTitle",
            key: "couponTitle",
            hideInSearch: true
        },
        {
            title: "用户id",
            dataIndex: "userId",
            key: "userId",
        },
        {
            title: "用户手机号",
            dataIndex: "memberMobile",
            key: "memberMobile",
        },
        {
            title: '身份',
            dataIndex: 'memberType',
            key: 'memberType',
            hideInSearch: true,
            valueEnum: {
                'R': { text: '注册会员' },
                'P': { text: '正式会员' },
                'S': { text: '商户会员' },
            },
        },
        {
            title: '状态',
            dataIndex: 'memberStatus',
            key: 'memberStatus',
            hideInSearch: true,
            valueEnum: {
                'Y': { text: '正常' },
                'N': { text: '冻结' },
            },
        },
        {
            title: "注册时间",
            dataIndex: "memberCreatedTimeString",
            key: "memberCreatedTimeString",
            hideInSearch: true
        },
        {
            title: "状态",
            dataIndex: "pushStatus",
            key: "pushStatus",
            valueEnum: {
                0: { text: '发送成功' ,status: 'Success' },
                1: { text: '发送失败' ,status: 'Error' },
            },
        },
    ]

    return <div>
        <GoBack title={"查看"}/>
        <ProTable
            actionRef={actionRef}
            scroll={{x: "max-content", y: '57vh'}}
            rowKey={(record) => record.memberId}
            bordered={true}
            options={false}
            columns={columns}
            pagination={{
                defaultPageSize: 10,
                position: ['bottomCenter'],
                showSizeChanger: false
            }}
            params={{
                couponTimerCenterId: location.state.id
            }}
            request={async (params, sort, filter) => {
                // 这里需要返回一个 Promise,在返回之前你可以进行数据转化
                // 如果需要转化参数可以在这里进行修改
                const res = await apiPostTimedTaskResult({
                    pageNo: params.current,
                    pageSize: params.pageSize,
                    ...params
                });
                return {
                    data: res.data,
                    // success 请返回 true，
                    // 不然 table 会停止解析数据，即使有数据
                    success: res.code === 0,
                    // 不传会使用 data 的长度，如果是分页一定要传
                    total: res.totalCount,
                };
            }}
            search={{
                optionRender: (searchConfig,formProps,dom)=>{
                    return dom.reverse()
                },
                collapsed: false,
                collapseRender: false
            }}
        />
    </div>
}
